package com.resou.reader.activity.friendboost;

import com.resou.reader.base.ResouBasePresenter;
import com.resou.reader.data.ResouxsRepository;
import com.resou.reader.utils.ToastUtil;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class FriendBoostPresenter extends ResouBasePresenter<FriendBoostContract.View> implements FriendBoostContract.Presenter {
    private static final String TAG = "FriendBoostPresenter";
    private final ResouxsRepository mRepository;

    public FriendBoostPresenter(FriendBoostContract.View view) {
        super(view);
        mRepository = ResouxsRepository.getInstance();
    }

    @Override
    public void loadFriendHelpList(String token) {
        addCompositeDisposable(
                mRepository.loadFriendHelpList(token)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(resultList -> {
                            if (resultList.getCode() == 0) {
                                mView.setFriendList(resultList.getData());
                            } else {
                                ToastUtil.makeLongToast(resultList.getMsg());
                            }
                        }, throwable -> mView.showError(throwable))
        );
    }

    @Override
    public void getUserInfo(String token) {
        addCompositeDisposable(
                mRepository.loadUserInfo(token)
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(loginData -> mView.showEnergyValue(loginData), throwable -> mView.showError(throwable))
        );
    }
}
